<template>
  <div>
    <div class="carNoBoxInput">
      <div class="carNoBoxInputDiv">

        <input
          class="inputBox"
          :value="licensePlateUnit[0]"
          @click="licensePlateDoor = true"
          readonly="readonly"
        />
        <input
          class="inputBox"
          :value="licensePlateUnit[1]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <span class="dot"></span>
        <input
          class="inputBox"
          :value="licensePlateUnit[2]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <input
          class="inputBox"
          :value="licensePlateUnit[3]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <input
          class="inputBox"
          :value="licensePlateUnit[4]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <input
          class="inputBox"
          :value="licensePlateUnit[5]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <input
          class="inputBox"
          :value="licensePlateUnit[6]"
          @click="licensePlateDoor = true"
          style="margin-left:1px"
          readonly="readonly"
        />
        <input
          class="inputBox"
          id="xnyInput"
          :value="licensePlateUnit[7]"
          @click="licensePlateDoor = true"
          style="border:2px solid #67C23A;margin-left:1px"
          readonly="readonly"
        />
      </div>
    </div>
    <div v-if="licensePlateDoor">
      <div
        v-if="licensePlateUnit.length < 1"
        class="carNoBox"
      >
        <span
          class="carNo"
          v-for="item in columns"
          :key="item"
          @click="pickOn(item)"
        >
          {{item}}
        </span>
        <span
          class="delBt"
          @click="delCarNo"
          style="margin-left: 6px;width: 42px"
        >删除</span>
      </div>
      <div
        v-if="licensePlateUnit.length >= 1"
        class="carNoBox"
      >
        <span
          class="carNo"
          v-for="item in numberColumns"
          :key="item"
          @click="pickOn(item)"
        >
          {{item}}
        </span>
        <div style="display: flex;align-items: center">
          <span
            class="delBt"
            style="margin-left: 6px;width: 42px"
            @click="delCarNo"
          >删除</span>
          <span
            class="delBt"
            style="margin-left: 6px;width: 42px;background-color:#67C23A"
            @click="confirm"
          >完成</span>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
// import store from '@/store';



export default {
  props: {
    caridChanged: Function,
    carid: String,
  },
  data () {
    let licensePlateUnit = [];
    if (this.$props.carid) {
      console.log('this.$props.carid :>> ', this.$props.carid);
      licensePlateUnit = this.$props.carid.split('');
    }

    return {
      licensePlateDoor: false,
      activeIndex: 0,
      licensePlateUnit: licensePlateUnit,
      columns: [//省缩写选择
        '京', '沪', '鄂', '湘', '川', '渝', '粤', '闽', '晋', '黑',

        '津', '浙', '豫', '赣', '贵', '青', '琼', '宁', '吉', '蒙',

        '冀', '苏', '皖', '桂', '云', '陕', '甘', '藏', '新', '辽',
        '鲁'],
      numberColumns: [
        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
        'A', 'B', 'C', 'D', 'E',
        'F', 'G', 'H',
        // 'I',
        'J', 'K', 'L', 'M', 'N',
        // 'O',
        'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z',
        '港', '澳', '学', '领', '警',
      ],
    };
  },
  methods: {
    pickOn (value) {
      this.licensePlateDoor = true;
      if (this.licensePlateUnit.length <= 7) {
        this.licensePlateUnit.push(value);
      }
    },
    delCarNo () {
      this.licensePlateUnit.pop();
    },
    confirm () {
      if (this.licensePlateUnit.length >= 7) {
        if (this.licensePlateUnit.length == 7) {
          document.getElementsByClassName('carNoBoxInput')[0].style.backgroundColor = '#409EFF';
        }
        else if (this.licensePlateUnit.length == 8) {
          document.getElementsByClassName('carNoBoxInput')[0].style.backgroundColor = '#67C23A';
          document.getElementById('xnyInput').style.borderColor = '#fff';
        }
        this.$props.caridChanged(this.licensePlateUnit.join(''));

        console.log("车牌是：" + this.licensePlateUnit.join(''));
        this.licensePlateDoor = false;
      }
    },
  }
}
</script>
 
 
<style scoped>
.carNo {
  border-radius: 6px;
  background: #fff;
  font-weight: bold;
  font-size: 20px;
  line-height: 20px;
  height: 20px;
  width: 20px;
  margin: 6px;
  padding: 6px;
  cursor: pointer;
}
.inputBox {
  border: 2px solid #fff;
  border-radius: 3px;

  color: white;
  height: 20px;
  line-height: 20px;
  width: 20px;
  font-size: 20px;
  text-align: center;
  background-color: transparent;
  outline: none;
  caret-color: rgba(0, 0, 0, 0);
}
input:focus {
  border-bottom: 3px solid #fff;
  transition: all 0.5s;
}
.dot {
  margin-bottom: 6px;
  background-color: #fff;
  height: 6px;
  width: 6px;
  border-radius: 50%;
  display: inline-block;
}
.delBt {
  background: #acb3bb;
  border-radius: 6px;
  display: inline-block;
  font-weight: bold;
  font-size: 20px;
  height: 28px;
  width: 28px;
  margin: 6px;
  padding: 12px;
  cursor: pointer;
}
.carNoBoxInput {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  /* height: 80px; */
  border-radius: 8px;
  margin: 12px 0;
  background: #909399;
}

.carNoBoxInputDiv {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  margin: 10px 0px;
  /* height: 80px; */
  /* border-radius: 8px;
  margin: 12px 0;
  background: #909399; */
}
.carNoBox {
  background: #d0d5d9;
  position: relative;
  width: 100%;
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  justify-items: center;
  align-items: center;
}
</style>